package com.cdtye.itps.cms.controller.warn;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdtye.common.webcore.web.AjaxJson;
import com.cdtye.itps.cms.dao.warn.entity.JcjcWarnInformation;
import com.cdtye.itps.cms.dao.warn.vo.JcjcWarnInformationVo;
import com.cdtye.itps.cms.service.warn.JcjcWarnInformationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

import static com.cdtye.common.webcore.web.AjaxJson.error;
import static com.cdtye.common.webcore.web.AjaxJson.success;

/**
 *  通知公告controller
 * @author wzw
 * @date 2021-11-23
 */
@Api(tags="预警信息-信息-接口")
@RestController
@RequestMapping("/warnInformation")
public class JcjcWarnInformationCotroller {

    @Autowired
    private JcjcWarnInformationService modelService;


    @ApiOperation(value = "保存或更新", notes = "返回对象最新数据")
    @PostMapping(value = "/saveOrUpdate")
    public AjaxJson<Object> saveOrUpdate(@Valid @RequestBody JcjcWarnInformationVo vo){
        return success(modelService.saveOrUpdate(vo));
    }

    @ApiOperation(value = "按ID删除")
    @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "String")
    @DeleteMapping(value = "/{id}")
    public AjaxJson deleteById(@PathVariable("id") String id) throws Exception {
        if(StringUtils.isBlank(id)){
            return error("未获取到参数");
        }
        modelService.deleteData(id);
        return success();
    }



    @ApiOperation(value = "按ID查询")
    @ApiImplicitParam(name = "id", value = "主键", required = true, dataType = "String")
    @GetMapping(value = "/searchById/{id}")
    public AjaxJson getById(@PathVariable("id") String id) {
        if(StringUtils.isBlank(id)){
            return error("未获取到参数");
        }
        return success(modelService.getById(id));
    }

    @ApiOperation(value = "列表查询")
    @GetMapping(value = "/list")
    public AjaxJson<List<JcjcWarnInformation>> list(JcjcWarnInformationVo vo){
        List<JcjcWarnInformation> result = modelService.list(vo);
        return success(result);
    }

    @ApiOperation(value = "分页查询")
    @PostMapping(value = "/listPage")
    public AjaxJson<IPage<Map<String, Object>>> listPage(@RequestBody JcjcWarnInformationVo vo){
        return success(modelService.listPage(vo));
    }

    @ApiOperation(value = "预警信息类型")
    @GetMapping(value = "/warnType")
    public AjaxJson<List<Map<String,Object>>> getWarnType()
    {
        return success(modelService.getWarnType());
    }

}
